package com.fone.player.view;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.fone.player.R;
import com.fone.player.util.ScreenUtil;

public class LegalNoticeDialog implements OnClickListener {

	private static final String TAG = "legalNoticeDialog";

	private AlertDialog dialog;
	private TextView title, content;
	private View.OnClickListener listener;

	public LegalNoticeDialog(Context context, String text) {
		AlertDialog.Builder builder = new Builder(context);

		View declarationView = LayoutInflater.from(context).inflate(R.layout.declaration_dialog, null);
		dialog = builder.create();

		content = (TextView) declarationView.findViewById(R.id.declaration_content);
		// TODO 获取法律声明
		content.setText(text);

		title = (TextView) declarationView.findViewById(R.id.declaration_title);
		title.setText("法律声明");

		Button changeSureBtn = (Button) declarationView.findViewById(R.id.declaration_sure);
		changeSureBtn.setOnClickListener(this);

		declarationView.setMinimumWidth((int) (ScreenUtil.getScreenWidthPix(context) * 0.85));// 设置dialog的宽度
		declarationView.setMinimumHeight((int) (ScreenUtil.getScreenHeightPix(context) * 0.85));// 设置dialog的高度

		dialog.setCanceledOnTouchOutside(false);
		dialog.setView(declarationView, 0, 0, 0, 0);
		dialog.show();
	}

	public void setListener(View.OnClickListener listener) {
		this.listener = listener;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.declaration_sure:
			if (listener != null) {
				listener.onClick(v);
			}
			dialog.cancel();
			break;
		default:
			break;
		}
	}

}
